/**
 * 获取用户信息2018/5/15
 */
let tools = {};
let app = getApp();

tools.onGetInfo = function (_this, _type) {
  let cancel = Boolean(wx.getStorageSync('cancel'));
  wx.getSetting({
    success(res) {
      if (!res.authSetting['scope.userInfo']) {
        if (_type == 1) {
          _this.setData({
            isShow: !cancel,
          });
        } else if (_type == 2) {
          if (!wx.getStorageSync('cancel')) {
            wx.navigateTo({
              url: '/ws_micro_shop/pages/auth/auth',
            });
          }
        }
      } else {
        wx.getUserInfo({
          success: function (res) {
            const systemInfo = wx.getSystemInfoSync();
            app.ws_micro_shoplogin(1).then(resp => {
              app.ws_micro_shoprequest({
                url: app.api.passport.info,
                data: {
                  user_info: JSON.stringify(res.userInfo),
                  brand: systemInfo.brand,
                  model: systemInfo.model,
                },
                method: 'POST',
                success: function (res) {},
              });
            })
          },
        });
      }
    },
  });
};

module.exports = tools;
